package test;

import org.xmap.ui.View;
import org.xmap.ui.ViewManager;
import org.xmap.ui.base.Window;
import org.xmap.ui.control.TextField;
import org.xmap.ui.views.TextAreaView;

public class TextFieldView extends TextAreaView {

    private TextField tf;

    public TextFieldView(View back) {
        super(back);
        this.setTitleText("输入框控件演示");
        this.addText("这是个输入框控件演示，可以通过按键来输入数字，也可以结合触笔键盘来用触笔输入，选择“焦点模式”子菜单来设置焦点，只有具有焦点才可以输入，选择“边框模式”子菜单可以显示或隐藏边框，选择“背景模式”子菜单可以设置背景为透明或可见，选择“对齐方式”子菜单来设置对齐。");
        this.tf = new TextField("输入文字：", "", null, 100, javax.microedition.lcdui.TextField.ANY, 0,
                this.getClientRect().height, this.getClientRect().width, 30, Window.ORIENT_LEFT_DOWN);
        this.addControls(tf);
        // this.tf.setTransparent(true);
        this.tf.setFocus(true);
        this.addLeftMenu("焦点模式", new String[]{"得到焦点", "失去焦点"});
        this.addLeftMenu("边框模式", new String[]{"边框显示", "边框隐藏"});
        this.addLeftMenu("背景模式", new String[]{"背景透明", "背景可见"});
        this.addLeftMenu("对齐方式", new String[]{"左对齐", "居中对齐", "右对齐"});
        this.addLeftMenu("清空");
        this.setRightMenu("返回");
    }
    // public void timeInterrupted() {
    // this.tf.setLineColor((int) System.currentTimeMillis());
    // this.tf.setTextColor((int) System.currentTimeMillis() + 0xffff0000);
    // }

    public void commandEvent(String command, Window sender) {
        if (command.equals("得到焦点")) {
            this.tf.setFocus(true);
        } else if (command.equals("失去焦点")) {
            this.tf.setFocus(false);
        } else if (command.equals("边框显示")) {
            this.tf.setDrawRect(true);
        } else if (command.equals("边框隐藏")) {
            this.tf.setDrawRect(false);
        } else if (command.equals("背景透明")) {
            this.tf.setTransparent(true);
        } else if (command.equals("背景可见")) {
            this.tf.setTransparent(false);
        } else if (command.equals("左对齐")) {
            this.tf.setAlign(Window.ALIGN_LEFT);
        } else if (command.equals("居中对齐")) {
            this.tf.setAlign(Window.ALIGN_CENTER);
        } else if (command.equals("右对齐")) {
            this.tf.setAlign(Window.ALIGN_RIGHT);
        } else if (command.equals("清空")) {
            this.tf.deleteAll();
        } else if (command.equals("返回")) {
            ViewManager.instance.setView(this.back, View.ANIMATION_LEFT_TO_RIGHT);
        }
    }
}
